package com.xiaoge.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoge.entity.EduCourse;
import com.xiaoge.entity.EduNavBar;
import com.xiaoge.exception.BusinessException;
import com.xiaoge.service.OssService;
import com.xiaoge.vo.EduAdvVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoge.mapper.EduAdvMapper;
import com.xiaoge.entity.EduAdv;
import com.xiaoge.service.EduAdvService;
import org.springframework.web.multipart.MultipartFile;

/**
* @Author: 冷俊杰
* @Description: TODO
* @DateTime: 2022/11/9 20:01
**/
@Service
public class EduAdvServiceImpl extends ServiceImpl<EduAdvMapper, EduAdv> implements EduAdvService{
    @Resource
    private OssService ossService;

    @Override
    public int InEduAdv(EduAdvVO vo, MultipartFile file) throws ParseException {
        vo.setAdvImg(ossService.upload(file));
        return this.baseMapper.InEduAdv(vo);
    }

    @Override
    public int UpEduAdv(EduAdvVO vo) {
        return this.baseMapper.UpEduAdv(vo);
    }

    @Override
    public Page<EduAdv> getEduAdvByPage(Page<EduAdv> page) {
        List<EduAdv> eduAdvList = this.baseMapper.ListEduAdv(page);
        if (eduAdvList.size()==0){
            throw new BusinessException("暂无数据");
        }
        //将刚刚动态sql查询的内容给page对象,让它去实现分页
        page.setRecords(eduAdvList);
        return page;
    }
}
